# =====================================
# 作者：老曹  QQ:1484743
# 版权声明：本程序为个人原创、开源程序，禁止用于任何违法用途，任何违法用途均与作者无关。
# 仅限学习交流，转载请注明出处。如需商用请联系作者。
# =====================================
# 宿主机硬盘SMART监控脚本（Windows版）
# 替换变量：{{HOST_ID}} {{TOKEN}}
$HostId = {{HOST_ID}}
$Token = "{{TOKEN}}"
$ApiUrl = "你的API地址/api/data/report"
$Device = "PhysicalDrive0"
$Smartctl = "C:\\Program Files\\smartmontools\\bin\\smartctl.exe"
if (!(Test-Path $Smartctl)) {
    Write-Host "请先手动安装 smartmontools 并配置环境变量"
    exit 1
}
$SmartJson = & $Smartctl -a -j /dev/$Device | Out-String
$Model = (& $Smartctl -i /dev/$Device | Select-String 'Device Model').ToString().Split(':')[1].Trim()
$Serial = (& $Smartctl -i /dev/$Device | Select-String 'Serial Number').ToString().Split(':')[1].Trim()
$Capacity = (& $Smartctl -i /dev/$Device | Select-String 'User Capacity').ToString() -replace '\D',''
$Body = @{hostId=$HostId; token=$Token; smart_json=$SmartJson; device=$Device; model=$Model; serial=$Serial; capacity=[int64]$Capacity} | ConvertTo-Json -Compress
Invoke-RestMethod -Uri $ApiUrl -Method Post -Body $Body -ContentType 'application/json'
# 可通过任务计划程序定时执行本脚本 